import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.receivingDealerName)
        requiredFields.push(
            formatMessage({
                id: 'validator.receivingDealerName',
                defaultMessage: '收货方'
            })
        );
    if(!data || !data.address)
        requiredFields.push(
            formatMessage({
                id: 'validator.address',
                defaultMessage: '地址'
            })
        );
    if(!data || !data.contactNumber)
        requiredFields.push(
            formatMessage({
                id: 'validator.contactNumber',
                defaultMessage: '联系电话'
            })
        );
    if(!data || !data.destination)
        requiredFields.push(
            formatMessage({
                id: 'validator.destination',
                defaultMessage: '目的地'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
